package atm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * 存款
 */
public class SavePanel extends JPanel implements ActionListener {
    private AtmGUI atmGUI;
    private JLabel moneyLabel = new JLabel("请输入存款金额：");
    private JTextField moneyTextField = new JTextField();
    private Font font = new Font("宋体",Font.BOLD,18);
    private JButton sureBtn = new JButton(new ImageIcon("images\\buttonSure.jpg"));
    private JButton offBtn = new JButton(new ImageIcon("images\\buttonOff.jpg"));
    public SavePanel(AtmGUI atmGUI){
        this.atmGUI = atmGUI;
        this.setLayout(null);
        this.setOpaque(false);
        moneyLabel.setBounds(300,200,200,50);
        moneyLabel.setFont(font);
        this.add(moneyLabel);
        moneyTextField.setBounds(450,200,250,50);
        moneyTextField.setFont(font);
        this.add(moneyTextField);
        sureBtn.setBounds(800,400,140,50);
        sureBtn.addActionListener(this);
        this.add(sureBtn);
        offBtn.setBounds(0,400,140,50);
        offBtn.addActionListener(this);
        this.add(offBtn);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        ArrayList<User> users = atmGUI.getUsers();
        Double saveMoney = Double.parseDouble(moneyTextField.getText());
        for (int i = 0;i < users.size();i++){
            users.get(i).setBlance(saveMoney + users.get(i).getBlance());
            JOptionPane.showMessageDialog(this,"存款成功");
            break;
        }
        moneyTextField.setText("");
       atmGUI.showPanel("menu");
    }
}
